package com.yunhui.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yunhui.entity.User;
import com.yunhui.mapper.UserMapper;
import com.yunhui.service.UserService;


import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  用户的业务处理的层实现类
 * </p>
 *
 * @author WGH
 * @since 2019-12-09
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    String phone = null;
    String email = null;
    @Override
    public User selectByPhoneOrEmail(String phone_email) {
        if(phone_email==null){
            return null;
        }

        if(phone_email.lastIndexOf(".")>-1){
            email = phone_email;
        }else{
            phone = phone_email;
        }

        return userMapper.selectByPhoneOrEmail(phone,email);
    }

    @Override
    public List<User> listByPage(int index, int size, String begin, String end, String phone_email) {

        if(phone_email!=null){
            if(phone_email.lastIndexOf(".")>-1){
                email = phone_email;
            }else{
                phone = phone_email;
            }
        }

        return userMapper.listByPage((index-1)*size,size,begin,end,phone,email);
    }

    @Override
    public int countByPage( String begin, String end, String phone_email) {

        if(phone_email!=null){
            if(phone_email.lastIndexOf(".")>-1){
                email = phone_email;
            }else{
                phone = phone_email;
            }
        }

        return userMapper.countByPage(begin,end,phone,email);
    }


}
